package com.blank.shop.hystrix.provider;

import com.blank.shop.hystrix.ShopHystrixApplication;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
 * @author _blank
 */
@Configuration
@Profile({ShopHystrixApplication.SERVER_PROVIDER})
public class MyHystrixServlet {

    @Bean
    public ServletRegistrationBean<HystrixMetricsStreamServlet> hystrixMetricsStreamServlet() {
        final HystrixMetricsStreamServlet servlet = new HystrixMetricsStreamServlet();
        final String[] urlMappings = {"/hystrix.stream"};

        final ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean = new ServletRegistrationBean<>(servlet, urlMappings);
        registrationBean.setName("hystrixMetricsStreamServlet");
        registrationBean.setLoadOnStartup(1);
        return registrationBean;
    }

}